package my.edu.model.bills.fund.service;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import my.edu.model.bills.fund.entity.OtherIncomeOrder;
import my.edu.model.bills.fund.entity.dto.InComeDetailDTO;
import my.edu.model.information.service.IAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import my.edu.model.bills.fund.entity.OtherIncomeOrderDetail;
import my.edu.model.bills.fund.mapper.OtherIncomeOrderDetailMapper;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.List;

@Service
public class OtherIncomeOrderDetailServiceImpl extends ServiceImpl<OtherIncomeOrderDetailMapper, OtherIncomeOrderDetail> implements IOtherIncomeOrderDetailService{

    @Autowired
    private IAccountService accountService;
    @Override
    @Transactional
    public void saveBatchByDTO(List<InComeDetailDTO> incomeDetailDTOList, OtherIncomeOrder otherIncomeOrder) {
        List<OtherIncomeOrderDetail> list = incomeDetailDTOList.stream().map(i -> {
            OtherIncomeOrderDetail otherIncomeOrderDetail = BeanUtil.copyProperties(i, OtherIncomeOrderDetail.class);
            otherIncomeOrderDetail.setOtherIncomeOrderId(otherIncomeOrder.getId());
            return otherIncomeOrderDetail;
        }).toList();
        saveBatch(list);
    }

    @Override
    @Transactional
    public void updateByDTO(List<InComeDetailDTO> incomeDetailDTOList, OtherIncomeOrder byId) {
    remove(Wrappers.<OtherIncomeOrderDetail>lambdaQuery().eq(OtherIncomeOrderDetail::getOtherIncomeOrderId, byId.getId()));
        saveBatchByDTO(incomeDetailDTOList, byId);
    }

    @Override
    public void removeByOrderId(List<Long> longs) {
        remove(Wrappers.<OtherIncomeOrderDetail>lambdaQuery().in(OtherIncomeOrderDetail::getOtherIncomeOrderId,longs));
    }

}
